<!--
 * @Author: your name
 * @Date: 2022-04-18 16:26:08
 * @LastEditTime: 2022-04-27 15:33:24
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \macc.admin.vue\src\views\system\usercenter\weixin.vue
-->
<template>
  <div class="wx">
    <a-row>
      <a-col :span="6">
        <div style="width: 100px">{{ $t('userCenter.bindingWeChat') }}</div>
      </a-col>
      <a-col :span="12">
        <div style="flex: 1; text-align: left; color: #999">
          {{
            userInfo.wechatState == 'UNBIND'
              ? ''
              : userInfo.wechatNickname || $t('userCenter.unbinded')
          }}
        </div>
      </a-col>

      <a-col :span="6">
        <div style="width: 100px">
          <a-button
            type="link"
            v-if="userInfo.wechatState == 'UNBIND'"
            @click="bind"
            >{{ $t('userCenter.bindingWeChat') }}</a-button
          >
          <a-button type="link" @click="unbind" v-else>{{
            $t('devices.unbind')
          }}</a-button>
        </div>
      </a-col>
    </a-row>
  </div>
</template>
<script>
import { mapState } from 'vuex';
export default {
  name: 'WeiXin',
  props: {
    userInfo: Object,
  },
  data() {
    return {};
  },
  computed: {
    ...mapState('User', ['sysConf']),
  },
  methods: {
    unbind() {
      // const maccAppid = this.sysConf?.wxAppid;
      // window.open(
      //   'https://open.weixin.qq.com/connect/qrconnect?appid=' +
      //     maccAppid +
      //     '&redirect_uri=' +
      //     encodeURIComponent(
      //       window.location.origin +
      //         window.location.pathname +
      //         '#/testBin?type=UNBIND'
      //     ) +
      //     '&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect',
      //   '微信登陆',
      //   'height=530,width=500,top=30,left=30,toolbar=no,menubar=no,scrollbars=no, resizable=no,status=no'
      // );
      this.$emit('unBindWx');
    },
    bind() {
      const maccAppid = this.sysConf?.wxAppid;
      console.log(this.sysConf, 'sysConf');
      console.log(maccAppid, 'maccAppid');
      window.open(
        'https://open.weixin.qq.com/connect/qrconnect?appid=' +
          maccAppid +
          '&redirect_uri=' +
          encodeURIComponent(
            window.location.origin +
              window.location.pathname +
              '#/testBin?type=BIND'
          ) +
          '&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect',
        '微信登陆',
        'height=530,width=500,top=30,left=30,toolbar=no,menubar=no,scrollbars=no, resizable=no,status=no'
      );
    },
  },
};
</script>
<style lang="less" scoped></style>
